package com.hxzy.jsp.connection;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class JNDIBBSConection implements BBSConection {

	@Override
	public Connection get() {
		Context ctx = null;
		try {
			ctx = new InitialContext();
			// 获取与逻辑名相关联的数据源对象
			DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/stu_jsp");
			return ds.getConnection();
		} catch (SQLException exception) {
			throw new RuntimeException(exception);
		} catch (NamingException namingException) {
			throw new RuntimeException(namingException);
		}
	}

	@Override
	public void close() {
		return;
	}

}
